package com.woniu.micropropertyserver.parkmag.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.microcommonsserver.entity.HouseInfoEntity;
import com.woniu.microcommonsserver.entity.ParkCarInfoEntity;
import com.woniu.microcommonsserver.entity.ParkInfoEntity;
import com.woniu.microcommonsserver.entity.ParkcarChangeInfoEntity;
import com.woniu.microcommonsserver.param.PageRequest;
import com.woniu.micropropertyserver.housemag.mapper.HouseMapper;
import com.woniu.micropropertyserver.parkmag.mapper.ParkMapper;
import com.woniu.micropropertyserver.parkmag.service.IParkService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ：pengchufeng
 * @date ：Created in 2021/2/1
 * @description：车位service接口实现
 */
@Transactional(readOnly = true)
@Service
public class ParkServiceImpl implements IParkService {

    @Resource
    private ParkMapper parkMapper;

    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    public PageInfo<ParkCarInfoEntity> findBy(PageRequest request, ParkCarInfoEntity parkCarInfoEntity) {
        return PageHelper.startPage(request.getPageNum(),request.getLimit()).
                doSelectPageInfo(()->parkMapper.findBy(request,parkCarInfoEntity));
    }

    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    public List<ParkcarChangeInfoEntity> findChange(String id) {
        return parkMapper.findChange(id);
    }

    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    public List<ParkInfoEntity> findPark() {
        return parkMapper.findPark();
    }

    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    public boolean addChange(ParkcarChangeInfoEntity parkcarChangeInfoEntity) {
        parkMapper.addChange(parkcarChangeInfoEntity);
        return true;
    }

    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    public boolean bind(ParkCarInfoEntity parkCarInfoEntity) {
        parkMapper.bind(parkCarInfoEntity);
        return true;
    }

    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    public boolean unbind(String hid) {
        parkMapper.unbind(hid);
        return true;
    }

    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    public boolean cBind(ParkCarInfoEntity parkCarInfoEntity) {
        parkMapper.cBind(parkCarInfoEntity);
        return true;
    }

    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    public boolean rent(ParkCarInfoEntity parkCarInfoEntity) {
        parkMapper.rent(parkCarInfoEntity);
        return true;
    }


    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    public boolean cRent(ParkCarInfoEntity parkCarInfoEntity) {
        parkMapper.cRent(parkCarInfoEntity);
        return true;
    }

    @Override
    public List<ParkCarInfoEntity> findParksByCard(String cardId) {
        return parkMapper.findByOCard(cardId);
    }
}
